import java.util.HashMap;
import java.util.Map;

public class Main {

    public int[] twoSum(int[] nums, int target) {
        int len = nums.length;
        //key 下标，value 为 nums 中的元素
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < len; i++) {
            if (map.containsKey(target - nums[i])) {
                return new int[]{map.get(target - nums[i]), i};
            }
            map.put(nums[i], i);
        }

        return null;
    }
}
